package edu.iiitb.studentinfo.service;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Map;

import com.opensymphony.xwork2.ActionContext;

import edu.iiitb.studentinfo.model.Student;
import edu.iiitb.studentinfo.util.DBconn;
 


public class EditProfileService {
	/*private Student studentBean;*/
	private int studentId;
	private DBconn dbconn = null;
	private Connection con = null;
	private PreparedStatement pst = null;
	private Statement stmt = null;
	
	private String query = null;
	
	public int UpdateProfile(String fname,String lname,String rollno,String email, String phone){
		
		Map session = ActionContext.getContext().getSession();
		studentId=(Integer) session.get("userid");
		//String query = "UPDATE student_information set firstName='"+?+"', set lastName=?, set RollNo=?, set email=?, set phone=? where studentid=?";
	String query = "UPDATE student_information set firstName='"+fname+"', lastName='"+lname+"', RollNo='"+rollno+"', email='"+email+"', phone='"+phone+"' where studentid='"+studentId+"' ";
		try {
			dbconn = new DBconn();
			con = dbconn.getConnection();
			pst = con.prepareStatement(query);
			/*pst.setString(1, fname);
			pst.setString(2, lname);
			pst.setString(3, rollno);
			pst.setString(4, email);
			pst.setString(5, phone);
			pst.setInt(6, studentId);*/
		    System.out.println(query);
			pst.executeUpdate();
			
		} catch (SQLException e) {
			System.out.println(e.getMessage());
			studentId = -1;
		} finally {
			dbconn.close(pst);
			dbconn.close(con);
		}
		
		
		
		
		
	return studentId;
		
		
		
		
		/*System.out.println("first name submit ="+studentBean.getFirstName());
		System.out.println("last name="+studentBean.getLastName());
		System.out.println("roll no="+studentBean.getRollNo());
		System.out.println("email="+studentBean.getEmail());*/
		
	}

}
